#include "Rss_UI_Manager.h"

Rss_UI_Manager* Rss_UI_Manager::p_manager = NULL;
Rss_UI_Manager* Rss_UI_Manager::GetManager() { return p_manager; }
Rss_UI_Manager::Rss_UI_Manager() { p_manager = this; }

void Rss_UI_Manager::Hide() 
{
	login.Hide();
	feed.Hide();
	info.Hide();
	items.Hide();
	feedItem.Hide();
	addfeed.Hide();
	local.Hide();
	searchfeed.Hide();
}

void Rss_UI_Manager::SetHandle(HWND h_wnd)
{
	login.SetHandle(h_wnd);
	feed.SetHandle(h_wnd);
	progress.SetHandle(h_wnd);
	info.SetHandle(h_wnd);
	items.SetHandle(h_wnd);
	feedItem.SetHandle(h_wnd);
	addfeed.SetHandle(h_wnd);
	local.SetHandle(h_wnd);
	searchfeed.SetHandle(h_wnd);
}

void Rss_UI_Manager::Show()
{		
	login.Show();
}

void Rss_UI_Manager::RefreshWindow()
{
	this->GetWnd()->Invalidate(0,true);
	this->GetWnd()->UpdateWindow();
}
void Rss_UI_Manager::UI_ShowInfo()
{
	this->Hide();
	info.Show();
}
void Rss_UI_Manager::UI_ShowLogin()
{
	this->Hide();
	login.Show();
}
void Rss_UI_Manager::UI_ShowFeeds()
{
	this->Hide();
	feed.Show();
}
void Rss_UI_Manager::UI_ShowFeedItems()
{
	this->Hide();
	items.Show();
}
void Rss_UI_Manager::UI_AddFeed()
{
	this->Hide();
	addfeed.Show();
}
void Rss_UI_Manager::UI_ViewFeedItem(MyListItemData* p_listdata,bool backToLocal)
{
	this->Hide();
	feedItem.SetData(p_listdata);
	feedItem.SetBackPos(backToLocal);
	feedItem.Show();
}
void Rss_UI_Manager::UI_ViewLocalItem(int backToLogin)
{
	this->Hide();
	if(backToLogin < 2)
		local.SetBackPos(backToLogin);
	local.Show();
}

void Rss_UI_Manager::UI_SearchFeed()
{
	this->Hide();
	searchfeed.Show();
}

LRESULT Rss_UI_Manager::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam)
{	
	if(!login.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!feed.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!progress.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!info.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!items.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!feedItem.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!addfeed.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!local.MzDefWndProc(message, wParam, lParam))
		return 0;
	if(!searchfeed.MzDefWndProc(message, wParam, lParam))
		return 0;
	return -1;
}

void Rss_UI_Manager::OnMzCommand(WPARAM wParam, LPARAM lParam)
{
	login.OnMzCommand(wParam, lParam);
	feed.OnMzCommand(wParam, lParam);
	progress.OnMzCommand(wParam, lParam);
	info.OnMzCommand(wParam, lParam);
	items.OnMzCommand(wParam, lParam);
	feedItem.OnMzCommand(wParam, lParam);
	addfeed.OnMzCommand(wParam, lParam);
	local.OnMzCommand(wParam, lParam);
	searchfeed.OnMzCommand(wParam, lParam);
}

void Rss_UI_Manager::OnTimer(UINT_PTR nIDEvent)
{
	progress.OnTimer(nIDEvent);
}